Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17-H0ngJu #195

Merged
merged 2 commits into from
May 26, 2024
Merged

17-H0ngJu #195

merged 2 commits into from
May 26, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented May 22, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์ ๋ก์ƒ‰์•ฝ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

1H 20M

โœจ ์ˆ˜๋„ ์ฝ”๋“œ


๋ฌธ์ œ ์š”์•ฝ
์ •์ƒ์ธ๊ณผ, ์ ๋…น์ƒ‰์•ฝ์ธ ์‚ฌ๋žŒ์ด ์ฃผ์–ด์ง„ ๊ทธ๋ฆผ์„ ๋ณด์•˜์„ ๋•Œ, ๊ฐ๊ฐ ๋ช‡ ๊ฐœ์˜ ๊ตฌ์—ญ์œผ๋กœ ๋ณด์ด๋Š”์ง€ ๋ฐ˜ํ™˜ํ•˜๋ผ@!

๊ท€์—ฌ์›Œ


bfs+๋ฐฑํŠธ๋ž˜ํ‚น์ด๋ผ๊ณ  ์ƒ๊ฐ์„ ํ–ˆ๊ณ 

์ฃผ์–ด์ง„ ๊ทธ๋ฆผ์—์„œ, R ๊ตฌ์—ญ์˜ ์ˆ˜, G ๊ตฌ์—ญ์˜ ์ˆ˜, B ๊ตฌ์—ญ์˜ ์ˆ˜๋ฅผ ๊ฐ๊ฐ ๋”ฐ๋กœ ๊ตฌํ•œ ๋’ค์—

์ •์ƒ์ธ์ด ๋ฐ”๋ผ๋ณด๋Š” ๊ตฌ์—ญ์˜ ๊ฐœ์ˆ˜๋Š” R + G + B,

์ ๋…น์ƒ‰์•ฝ์ธ ๊ฒฝ์šฐ R + B๋กœ ๋‹จ์ˆœํ•˜๊ฒŒ ๊ตฌํ•˜๋ ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค



์ ์ƒ‰๊ณผ ๋…น์ƒ‰์„ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š์•„๋„ ๋˜๋ฏ€๋กœ G๋ฅผ ์•ˆ ์„ธ๋ฉด ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.

์ฆ‰, ์ฃผ์–ด์ง„ ๊ทธ๋ฆผ์—์„œ R์„ G๋กœ ๋ฐ”๊พธ์ง€ ์•Š์•„๋„ ๊ฐ€๋Šฅํ•  ๊ฒƒ์ด๋ผ๊ณ  ์˜ˆ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ๋ณด๊ธฐ
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
arr = [[i for i in input()]for _ in range(N)]
visited = [[0] * N for _ in range(N)]
direc = [(1,0), (-1,0), (0,1), (0,-1)]
result = [0, 0, 0] # R G B ๊ตฌ์—ญ ์ˆ˜

def dfs(x, y, color):
    visited[x][y] = 1
    for dx, dy in direc:
        nx = dx + x
        ny = dy + y
        if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny] and arr[nx][ny] == color:
            dfs(nx, ny, color)

def solution(color):
    cnt = 0
    for i in range(N):
        for j in range(N):
            if not visited[i][j] and arr[i][j] == color:
                dfs(i,j,color)
                cnt += 1

    return cnt

result[0] = solution("R")
visited = [[0] * N for _ in range(N)]
result[1] = solution("G")
visited = [[0] * N for _ in range(N)]
result[2] = solution("B")

print(result[0]+result[1]+result[2], result[0]+result[2], end=" ")

์˜ค ์‰ฌ์šด๋ฐ? ํ•˜๊ณ  ์ œ์ถœํ–ˆ๋”๋‹ˆ 'ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค'๊ฐ€ ๋–ด์Šต๋‹ˆ๋‹ค ใ…Ž;;

์•„๋ž˜์˜ ๊ฒฝ์šฐ๊ฐ€ ๋ฐ˜๋ก€์ž…๋‹ˆ๋‹ค.




์ •์ƒ์ธ์˜ ๊ฒฝ์šฐ R = 2, G = 2, B = 0์ด๋ฏ€๋กœ, 4์ž…๋‹ˆ๋‹ค.


๋‹จ์ˆœํžˆ ์ ๋…น์ƒ‰์•ฝ์ธ ๊ฒฝ์šฐ R + B๋กœ ๊ณ„์‚ฐํ•˜๊ฒŒ ๋˜๋ฉด, 2๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.


ํ•˜์ง€๋งŒ, ์‹ค์ œ๋กœ ์ ๋…น์ƒ‰์•ฝ์ด ๋ฐ”๋ผ๋ณด๋Š” ๊ตฌ์—ญ์˜ ๊ฐœ์ˆ˜๋Š” 1์ž…๋‹ˆ๋‹ค.




R์ด๋ž‘ G ๋ฐ”๊พธ์ง€ ์•Š์•„๋„ ์ ๋…น์ƒ‰์•ฝ์˜ ๊ตฌ์—ญ ์ˆ˜๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์„๊ฑฐ๋ผ๋Š” ์ƒ๊ฐ๊ณผ๋Š” ๋‹ฌ๋ฆฌ,


์œ„์˜ ๊ฒฝ์šฐ์—์„œ ๊ฒฐ๊ตญ R๊ณผ G๋ฅผ ๋ฐ”๊ฟ”์ค€ ํ›„, ๊ตฌ์—ญ ์ˆ˜๋ฅผ ์„ธ์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๊นจ๋‹ซ๊ณ  ๋กœ์ง์„ ๊ณ ์ณค์Šต๋‹ˆ๋‹ค !


์ตœ์ข… ์ˆ˜๋„ ์ฝ”๋“œ

  1. ์ •์ƒ์ธ์˜ ๊ฒฝ์šฐ
    1. ์•„์ง ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๋…ธ๋“œ๋ผ๋ฉด q์— ๋„ฃ๊ณ  visited ๊ฐฑ์‹ 
    2. q๊ฐ€ ๋นŒ ๋™์•ˆ ์•„๋ž˜๋ฅผ ์ˆ˜ํ–‰
      1. ํ˜„์žฌ ์œ„์น˜ pop
      2. ๋งŒ์•ฝ ๋‹ค์Œ ์œ„์น˜(์ƒํ•˜์ขŒ์šฐ)๊ฐ€ ์ƒ‰์ด ๊ฐ™์œผ๋ฉด q์— ๋„ฃ๊ณ  ๋‹ค์‹œ visited ๊ฐฑ์‹ 
  2. ์ ๋…น ์ƒ‰์•ฝ์˜ ๊ฒฝ์šฐ
    0. ๋จผ์ € R์„ G๋กœ ๋ฐ”๊ฟ”์ฃผ๊ณ  ์ •์ƒ์ธ๊ณผ ๊ฐ™์€ ๋กœ์ง ์ˆ˜ํ–‰

import sys
sys.setrecursionlimit(10**6)
from collections import deque

def input(): return sys.stdin.readline().rstrip()

N = int(input())
arr = [[i for i in input()]for _ in range(N)]
visited = [[0] * N for _ in range(N)]
direc = [(1,0), (-1,0), (0,1), (0,-1)]
result = [0, 0]

def bfs(x, y, color):
    q = deque([(x,y)])
    visited[x][y] = 1
    while q:
        cx, cy = q.popleft()
        for dx, dy in direc:
            nx = dx + cx
            ny = dy + cy
            if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny] and arr[nx][ny] == color:
                q.append((nx, ny))
                visited[nx][ny] = 1


for i in range(N):
    for j in range(N):
        if not visited[i][j]:
            bfs(i,j,arr[i][j])
            result[0] += 1

visited = [[0] * N for _ in range(N)]

for i in range(N):
    for j in range(N):
        if arr[i][j] == "R":
            arr[i][j] = "G"

for i in range(N):
    for j in range(N):
        if not visited[i][j]:
            bfs(i,j,arr[i][j])
            result[1] += 1


print(result[0], result[1], end=" ")

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

Copy link
Collaborator

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„.. G ๋ฅผ R ๋กœ ๋ฐ”๊ฟ€ ์ƒ๊ฐ์„ ๋ชปํ•˜๊ณ  bfs ์ฝ”๋“œ๋ฅผ ๋‘๊ฐœ ์งœ๋ฒ„๋ ธ๋„ค์š”..ใ…‹ใ…‹
ํ™์ฃผ๋‹˜ ๋ฐฉ๋ฒ•์œผ๋กœ ๋‹ค์‹œ ์ž‘์„ฑํ•ด๋ดค์Šต๋‹ˆ๋‹ค..!

image

์ฝ”๋“œ ๊ธธ์ด๋„ ์‹œ๊ฐ„๋„ ๋” ์ค„์—ˆ๋„ค์š”!

import java.io.BufferedReader
import java.io.InputStreamReader

private lateinit var visited: Array<Array<Boolean>>
private lateinit var graph: Array<Array<String>>

private val dxdy = listOf((0 to 1), (0 to -1), (1 to 0), (-1 to 0))
fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()

    graph = Array(n) { Array(n) { "" } }

    repeat(n) {
        val line = br.readLine().chunked(1)
        line.forEachIndexed { index, value -> graph[it][index] = value }
    }

    visited = Array(n) { Array(n) { false } }
    var count = 0
    var countRG = 0
    for (x in 0 until n) {
        for (y in 0 until n) {
            if (bfs(x, y, n)) count++
        }
    }
    visited = Array(n) { Array(n) { false } }
    for (x in 0 until n) {
        for (y in 0 until n) {
            if (bfsRG(x, y, n)) countRG++
        }
    }

    println("$count $countRG")
}

private fun bfs(x: Int, y: Int, n: Int): Boolean {
    if (visited[x][y]) {
        return false
    }
    val q = ArrayDeque<Pair<Int, Int>>()
    q.add(x to y)
    val color = graph[x][y]
    while (q.isNotEmpty()) {
        val now = q.removeFirst()
        for (i in 0..3) {
            val nextX = now.first + dxdy[i].first
            val nextY = now.second + dxdy[i].second
            if (nextX >= n || nextY >= n || nextX < 0 || nextY < 0) {
                continue
            }
            val nextColor = graph[nextX][nextY]
            if (visited[nextX][nextY]) {
                continue
            }
            if (color != nextColor) {
                continue
            }
            visited[nextX][nextY] = true
            q.add(nextX to nextY)
        }
    }
    return true
}

private fun bfsRG(x: Int, y: Int, n: Int): Boolean {
    if (visited[x][y]) {
        return false
    }
    val q = ArrayDeque<Pair<Int, Int>>()
    q.add(x to y)
    val color = graph[x][y]
    while (q.isNotEmpty()) {
        val now = q.removeFirst()
        for (i in 0..3) {
            val nextX = now.first + dxdy[i].first
            val nextY = now.second + dxdy[i].second
            if (nextX >= n || nextY >= n || nextX < 0 || nextY < 0) {
                continue
            }
            val nextColor = graph[nextX][nextY]
            if (visited[nextX][nextY]) {
                continue
            }
            if (color != nextColor && (color == "B" || nextColor == "B")) {
                continue
            }
            visited[nextX][nextY] = true
            q.add(nextX to nextY)
        }
    }
    return true
}

G ๋ฅผ R ๋กœ ๋ฐ”๊พธ๊ณ  ์‹คํ–‰ : bfs ์ฝ”๋“œ๋Š” ํ•œ๊ฐœ

import java.io.BufferedReader
import java.io.InputStreamReader

private lateinit var visited: Array<Array<Boolean>>
private lateinit var graph: Array<Array<String>>

private val dxdy = listOf((0 to 1), (0 to -1), (1 to 0), (-1 to 0))
fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()

    graph = Array(n) { Array(n) { "" } }

    repeat(n) {
        val line = br.readLine().chunked(1)
        line.forEachIndexed { index, value -> graph[it][index] = value }
    }

    visited = Array(n) { Array(n) { false } }
    var count = 0

    for (x in 0 until n) {
        for (y in 0 until n) {
            if (bfs(x, y, n)) count++
        }
    }

    for (x in 0 until n) {
        for (y in 0 until n) {
            if (graph[x][y] == "G") {
                graph[x][y] = "R"
            }
        }
    }

    var countRG = 0
    visited = Array(n) { Array(n) { false } }
    for (x in 0 until n) {
        for (y in 0 until n) {
            if (bfs(x, y, n)) countRG++
        }
    }

    println("$count $countRG")
}

private fun bfs(x: Int, y: Int, n: Int): Boolean {
    if (visited[x][y]) {
        return false
    }
    val q = ArrayDeque<Pair<Int, Int>>()
    q.add(x to y)
    val color = graph[x][y]
    while (q.isNotEmpty()) {
        val now = q.removeFirst()
        for (i in 0..3) {
            val nextX = now.first + dxdy[i].first
            val nextY = now.second + dxdy[i].second
            if (nextX >= n || nextY >= n || nextX < 0 || nextY < 0) {
                continue
            }
            val nextColor = graph[nextX][nextY]
            if (visited[nextX][nextY]) {
                continue
            }
            if (color != nextColor) {
                continue
            }
            visited[nextX][nextY] = true
            q.add(nextX to nextY)
        }
    }
    return true
}

Copy link

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ œ ๊ฒฝ์šฐ์—” 1. ์ผ๋ฐ˜์ธ์šฉ ๋ณด๋“œ 2. ์ ๋ก์ƒ‰์•ฝ์šฉ ๋ณด๋“œ 2๊ฐ€์ง€๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ฐ ๋ณด๋“œ์— ๋Œ€ํ•ด dfs๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์‹์œผ๋กœ ํ’€์—ˆ์—ˆ๋„ค์š” :)
์ ๋ก์ƒ‰์•ฝ์ผ ๊ฒฝ์šฐ R์ด๋‚˜ G๋ฅผ ๋‹ค๋ฅธ ํ•œ์ชฝ์œผ๋กœ ํ†ต์ผ์‹œํ‚ค๋Š” ๊ฒŒ ์ด ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” key๋ผ๊ณ  ์ƒ๊ฐ๋ฉ๋‹ˆ๋‹ค :)

#include <iostream>
#include <vector>

using namespace std;

int N;

void dfs(vector<vector<char>> &grid, int x, int y, char color) {
  if (x < 0 || x >= N || y < 0 || y >= N) {
    return;
  }

  if (grid[x][y] != color) {
    return;
  }

  grid[x][y] = 'A';

  dfs(grid, x - 1, y, color);
  dfs(grid, x, y + 1, color);
  dfs(grid, x + 1, y, color);
  dfs(grid, x, y - 1, color);
 }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;

  vector<vector<char>> grid1, grid2;
  grid1.resize(N, vector<char>(N));
  grid2.resize(N, vector<char>(N));

  char ch;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> ch;
      grid1[i][j] = ch;
      
      if (ch == 'R') {
        ch = 'G';
      }
      grid2[i][j] = ch;
    }
  }

  int count1 = 0, count2 = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (grid1[i][j] != 'A') {
        dfs(grid1, i, j, grid1[i][j]);
        count1 += 1;
      }

      if (grid2[i][j] != 'A') {
        dfs(grid2, i, j, grid2[i][j]);
        count2 += 1;
      }
    }
  }

  cout << count1 << " " << count2;

  return 0;
}

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BFS/DFS๋กœ ํ’€๋ฆด ๊ฑฐ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๋กœ๋„ ํ’€๋ฆด ๊ฒƒ ๊ฐ™์•„์„œ ํŠธ๋ผ์ด ํ•ด๋ดค๋Š”๋ฐ ์™œ ์•ˆ๋˜๋Š” ์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š” .......... ๋„์™€์ฃผ์„ธ์š” ใ… ใ… ใ… ใ… ใ… ใ… ใ… 

from collections import Counter
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

board = []

def find_parent(graph, element):
    if graph[element] == element: return element
    parent = graph[element]
    graph[element] = find_parent(graph, parent)
    return graph[element]

def union(graph, first, second):
    x = find_parent(graph, first)
    y = find_parent(graph, second)
    if x == y: return

    x, y = min(x, y), max(x, y)
    graph[y] = x
    return

normal_parent = []
color_blindness_parent = []

idx = 0
for _ in range(N):
    row = list(input())
    
    for element in row:
        normal_parent.append(idx)
        color_blindness_parent.append(idx)
        idx += 1

    board.append(row)

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

for row in range(N):
    for col in range(N):

        for dir in range(4):
            new_row = row + dy[dir]
            new_col = col + dx[dir]

            if new_row < 0 or new_row >= N: continue
            if new_col < 0 or new_col >= N: continue

            if board[row][col] == board[new_row][new_col]:
                union(normal_parent, ((N * row) + col), ((N * new_row) + new_col))

            if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
                union(color_blindness_parent, (N * row + col), (N * new_row + new_col))

print(len(Counter(normal_parent).keys()), len(Counter(color_blindness_parent).keys()))






๊ฒฐ๊ตญ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ ํฌ๊ธฐํ•˜๊ณ  BFS๋กœ ํ‹€์—ˆ์”๋‹ˆ๋‹ค..

from collections import deque
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

idx = 0
board = []
for _ in range(N):
    board.append(list(input()))

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

visited = set()
deq = deque()
normal_answer = 0
for row in range(N):
    for col in range(N):
        if (row, col) in visited: continue
    
        normal_answer += 1
        visited.add((row, col))
        deq.append((row, col))

        while deq:
            now_row, now_col = deq.popleft()

            for dir in range(4):
                new_row = now_row + dy[dir]
                new_col = now_col + dx[dir]

                if new_row < 0 or new_row >= N: continue
                if new_col < 0 or new_col >= N: continue
                if (new_row, new_col) in visited: continue

                if board[row][col] == board[new_row][new_col]:
                    deq.append((new_row, new_col))
                    visited.add((new_row, new_col))

visited = set()
deq = deque()
color_blindness_answer = 0
for row in range(N):
    for col in range(N):
        if (row, col) in visited: continue

        color_blindness_answer += 1
        visited.add((row, col))
        deq.append((row, col))

        while deq:
            now_row, now_col = deq.popleft()

            for dir in range(4):
                new_row = now_row + dy[dir]
                new_col = now_col + dx[dir]

                if new_row < 0 or new_row >= N: continue
                if new_col < 0 or new_col >= N: continue
                if (new_row, new_col) in visited: continue

                if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
                    deq.append((new_row, new_col))
                    visited.add((new_row, new_col))

print(normal_answer, color_blindness_answer)







์™€ ๊ทผ๋ฐ R์ด๋ž‘ G ๋˜‘๊ฐ™์ด ๋งž์ถ”๊ณ  ๋‹ค์‹œ ๋Œ๋ฆฌ๋Š” ๊ฑฐ ๋ค ์ „๋‘๋‹ค ๋ค ์ „๋‘

Comment on lines +34 to +37
for i in range(N):
for j in range(N):
if arr[i][j] == "R":
arr[i][j] = "G"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ R์ด๋ž‘ G ๋˜‘๊ฐ™์ด ๋งŒ๋“œ๋Š” ๊ฑฐ ๋ฏธ์ณค๋‹ค..

@alstjr7437
Copy link
Member

์ฝ”๋“œ๊ฐ€ ์กฐ๊ธˆ ๋”๋Ÿฝ๊ฒŒ ๋‚˜์™”๋„ค์š” ์ €๋Š”...
๊ทผ๋ฐ ์ „์ฒด ๋กœ์ง์ด ๋˜‘๊ฐ™์•„์„œ ์‹ ๊ธฐํ–ˆ์Šต๋‹ˆ๋‹ค!!!

from collections import deque
import sys

dx = [0,0,-1,1]
dy = [1,-1,0,0]

input = sys.stdin.readline

n = int(input())
visited = [[False] * n for _ in range(n)] 
graph = [list(input().rstrip()) for _ in range(n)]
queue = deque()
result = 0


def bfs():
    global result 
    while queue:
        x, y, color = queue.popleft()
        for i in range(4):
            nx, ny= x + dx[i], y + dy[i]
            if nx < 0 or nx >= n or ny < 0 or ny >= n:
                continue
            if color == graph[ny][nx] and not visited[ny][nx] :
                queue.append((nx, ny, color))
                visited[ny][nx] = True
    result += 1

def resultCount():
    global result 
    for y in range(n):
        for x in range(n):
            if not visited[y][x] :
                queue.append((x, y, graph[y][x]))
                visited[y][x] = True
                bfs()
    print(result, end=" ")
    result = 0

# ์ ๋ก์ƒ‰์•ฝ ์•„๋‹๋•Œ ์ถœ๋ ฅ
resultCount()

# ์ ๋ก์ƒ‰์•ฝ ์ ์šฉ ๋ถ€๋ถ„
for y in range(n):
    for x in range(n):
        visited[y][x] = False
        if graph[y][x] == "G":
            graph[y][x] = "R"

# ์ ๋ก์ƒ‰์•ฝ ์ผ๋•Œ ์ถœ๋ ฅ
resultCount()      

bfs(i,j,arr[i][j])
result[0] += 1

visited = [[0] * N for _ in range(N)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R,G์„ ๋‹ค์‹œ ๋ฐ”๊พธ๋Š”๊ฒŒ ๊ฐ™์•„์„œ ํ™•์ธํ•ด๋ณด๋‹ˆ ์–ด์งœํ”ผ ๋ชจ๋“  graph๋ฅผ ๋„๋Š”๋ฐ
๊ทธ๋ž˜์„œ ์ €๋Š” ์ด๋ถ€๋ถ„์—์„œ ๊ทธ๋ƒฅ visited๋ฅผ ์ƒˆ๋กœ ๋งŒ๋“ค์ง€ ์•Š๊ณ  False๋กœ ์ดˆ๊ธฐํ™”๋ฅผ ํ•ด์คฌ์Šต๋‹ˆ๋‹ค!

for y in range(n):
    for x in range(n):
        visited[y][x] = False
        if graph[y][x] == "G":
            graph[y][x] = "R"

for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[0] += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result ๋ฐฐ์—ด ๋‘๊ฐœ ๋งŒ๋“ค์–ด๋‘๊ณ  ๊ฐ ๋ถ€๋ถ„์— ๋งž๊ฒŒ ์ถ”๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์—ˆ๊ตฐ์š” ใ„ทใ„ทใ„ทใ„ทใ„ทใ„ทใ„ท
์ €๋Š” ์ถœ๋ ฅํ•˜๊ณ  ๋‹ค์‹œ ์ดˆ๊ธฐํ™” ํ•ด์ฃผ๋Š” ํ˜•์‹์œผ๋กœ ํ–ˆ๋Š”๋ฐ ์ด ๋ฐฉ๋ฒ•์ด ๋” ์ข‹์€ ๊ฒƒ ๊ฐ™๋„ค์š”!

@H0ngJu
Copy link
Collaborator Author

H0ngJu commented May 26, 2024

BFS/DFS๋กœ ํ’€๋ฆด ๊ฑฐ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๋กœ๋„ ํ’€๋ฆด ๊ฒƒ ๊ฐ™์•„์„œ ํŠธ๋ผ์ด ํ•ด๋ดค๋Š”๋ฐ ์™œ ์•ˆ๋˜๋Š” ์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š” .......... ๋„์™€์ฃผ์„ธ์š” ใ… ใ… ใ… ใ… ใ… ใ… ใ… 

from collections import Counter
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

board = []

def find_parent(graph, element):
    if graph[element] == element: return element
    parent = graph[element]
    graph[element] = find_parent(graph, parent)
    return graph[element]

def union(graph, first, second):
    x = find_parent(graph, first)
    y = find_parent(graph, second)
    if x == y: return

    x, y = min(x, y), max(x, y)
    graph[y] = x
    return

normal_parent = []
color_blindness_parent = []

idx = 0
for _ in range(N):
    row = list(input())
    
    for element in row:
        normal_parent.append(idx)
        color_blindness_parent.append(idx)
        idx += 1

    board.append(row)

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

for row in range(N):
    for col in range(N):

        for dir in range(4):
            new_row = row + dy[dir]
            new_col = col + dx[dir]

            if new_row < 0 or new_row >= N: continue
            if new_col < 0 or new_col >= N: continue

            if board[row][col] == board[new_row][new_col]:
                union(normal_parent, ((N * row) + col), ((N * new_row) + new_col))

            if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
                union(color_blindness_parent, (N * row + col), (N * new_row + new_col))

print(len(Counter(normal_parent).keys()), len(Counter(color_blindness_parent).keys()))

๊ฒฐ๊ตญ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ ํฌ๊ธฐํ•˜๊ณ  BFS๋กœ ํ‹€์—ˆ์”๋‹ˆ๋‹ค..

from collections import deque
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

idx = 0
board = []
for _ in range(N):
    board.append(list(input()))

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

visited = set()
deq = deque()
normal_answer = 0
for row in range(N):
    for col in range(N):
        if (row, col) in visited: continue
    
        normal_answer += 1
        visited.add((row, col))
        deq.append((row, col))

        while deq:
            now_row, now_col = deq.popleft()

            for dir in range(4):
                new_row = now_row + dy[dir]
                new_col = now_col + dx[dir]

                if new_row < 0 or new_row >= N: continue
                if new_col < 0 or new_col >= N: continue
                if (new_row, new_col) in visited: continue

                if board[row][col] == board[new_row][new_col]:
                    deq.append((new_row, new_col))
                    visited.add((new_row, new_col))

visited = set()
deq = deque()
color_blindness_answer = 0
for row in range(N):
    for col in range(N):
        if (row, col) in visited: continue

        color_blindness_answer += 1
        visited.add((row, col))
        deq.append((row, col))

        while deq:
            now_row, now_col = deq.popleft()

            for dir in range(4):
                new_row = now_row + dy[dir]
                new_col = now_col + dx[dir]

                if new_row < 0 or new_row >= N: continue
                if new_col < 0 or new_col >= N: continue
                if (new_row, new_col) in visited: continue

                if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
                    deq.append((new_row, new_col))
                    visited.add((new_row, new_col))

print(normal_answer, color_blindness_answer)

์™€ ๊ทผ๋ฐ R์ด๋ž‘ G ๋˜‘๊ฐ™์ด ๋งž์ถ”๊ณ  ๋‹ค์‹œ ๋Œ๋ฆฌ๋Š” ๊ฑฐ ๋ค ์ „๋‘๋‹ค ๋ค ์ „๋‘

์œ ๋‹ˆ์˜จํŒŒ์ธ๋“œ ์ฝ”๋“œ ๋ฐ˜๋ก€ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค

20
BBBBBRRRRRRRRRRRBBBB
BBBBBRRRRRRRRRRRBBBB
RBBBBBRRRRRRRRRRBBBB
RRRBBBBRRRRRRRRRBBBB
RRRBBBBRRRRRRRRRRBRB
GRRBBBBRRRRRRRRRRBRR
GGRRRRBBBRRRRRRRRBBB
GGGRRRBBBRRRRRRRRBBB
RRGGGGBBBRRRRRRRRBBB
BBGGGGBBBBRRRRRRRBBB
BBGGGGGBBBRRRRRRRBBB
GBGGGGGBRRRRRRRRRBBB
GGGGGGGGRRRRRRRRRBBB
GGGGGGGGGRRRRRRRRBBB
GGGGGGGGGGRRRRRRRBBB
RRGGGGGGGGGGRRRRRRBB
RRGGGGGGGGGGGGGGGRBB
RRRGGGGGGGGGGGGGGRBB
GGGGGGGBGGGGGGGGGGBB
RRRRGGGGGGGGGGGGGGGG

๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋‹ต์€ 11 6์ธ๋ฐ 12 7์ด ๋‚˜์˜ค๋„ค์šฉ

ํ•˜ ๊ทผ๋ฐ ์™œ ์•ˆ๋˜๋Š”์ง€๋Š” ์ €๋„ ์•„์ง ๋ชป์ฐพ๊ฒ ๋„ค์š”.. ์ซŒ ๋” ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šด๋‘ฅ

=======
@tgyuuAn ์ฐพ์•˜์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

for i in range(len(normal_parent)):
    print(i, " : ", normal_parent[i])

๋ฅผ ๋Œ๋ฆฌ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ๋‚˜์™€์š”

image

๊ทธ๋Ÿฐ๋ฐ ์‹ค์ œ๋กœ 361๋ฒˆ์งธ ๊ฐ’์„ ๋ณด๋ฉด ๋ถ€๋ชจ๊ฐ€ 100์ด์–ด์•ผ ํ•˜๋Š”๋ฐ ๋ถ€๋ชจ๊ฐ€ 360์œผ๋กœ ๋˜์–ด ์žˆ์–ด์š”(0~400๋ฒˆ๊ธฐ์ค€์œผ๋กœ index๋ฅผ ์žก์€ ๊ฒฝ์šฐ์ž…๋‹ˆ๋‹ค)

๊ทธ๋ž˜์„œ

image

print ์ถœ๋ ฅํ•ด์„œ ๋Œ๋ ค๋ณด๋‹ˆ๊นŒ
graph[360] ๊ฐ’์ด 100์œผ๋กœ ๋ณ€๊ฒฝ๋˜๊ธฐ ์ „์— ์ด๋ฏธ graph[361]์„ 360์œผ๋กœ ๋ฐ”๊ฟจ๊ธฐ ๋•Œ๋ฌธ์— graph[361] 100์œผ๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ์•ˆ๋œ ๊ฒƒ ๊ฐ™์•„์š”!!

๊ทธ๋ž˜์„œ

์ตœ์ข… print ๋ฌธ์„ ์ถœ๋ ฅํ•˜๊ธฐ ์ „์—, ํ•œ๋ฒˆ๋” find_parent()๋ฅผ ๋Œ๋ ค์„œ ๋ถ€๋ชจ๋…ธ๋“œ๋ฅผ ๊ฐ€๋ฅดํ‚ค๋„๋ก ๋‹ค์‹œ ์—…๋ฐ์ดํŠธ ํ•ด์ฃผ์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค....

์• ๋ ต๋„ค์š”
์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๊ฐ€ ์›๋ž˜ ์ด๋Ÿฐ ๊ฒฝ์šฐ๋ฅผ ๋‹ค ์ƒ๊ฐํ•ด์ฃผ์–ด์•ผ ํ• ๊นŒ์š”................???

@H0ngJu H0ngJu closed this May 26, 2024
@H0ngJu H0ngJu reopened this May 26, 2024
@H0ngJu H0ngJu merged commit 3fa8bfb into main May 26, 2024
3 checks passed
@H0ngJu H0ngJu deleted the 17-H0ngJu branch May 26, 2024 10:29
@tgyuuAn
Copy link
Member

tgyuuAn commented May 27, 2024

BFS/DFS๋กœ ํ’€๋ฆด ๊ฑฐ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๋กœ๋„ ํ’€๋ฆด ๊ฒƒ ๊ฐ™์•„์„œ ํŠธ๋ผ์ด ํ•ด๋ดค๋Š”๋ฐ ์™œ ์•ˆ๋˜๋Š” ์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š” .......... ๋„์™€์ฃผ์„ธ์š” ใ… ใ… ใ… ใ… ใ… ใ… ใ… 

from collections import Counter

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

board = []

def find_parent(graph, element):

if graph[element] == element: return element
parent = graph[element]
graph[element] = find_parent(graph, parent)
return graph[element]

def union(graph, first, second):

x = find_parent(graph, first)
y = find_parent(graph, second)
if x == y: return
x, y = min(x, y), max(x, y)
graph[y] = x
return

normal_parent = []

color_blindness_parent = []

idx = 0

for _ in range(N):

row = list(input())
for element in row:
    normal_parent.append(idx)
    color_blindness_parent.append(idx)
    idx += 1
board.append(row)

dx = [0, 0, -1, 1]

dy = [-1, 1, 0, 0]

for row in range(N):

for col in range(N):
    for dir in range(4):
        new_row = row + dy[dir]
        new_col = col + dx[dir]
        if new_row < 0 or new_row >= N: continue
        if new_col < 0 or new_col >= N: continue
        if board[row][col] == board[new_row][new_col]:
            union(normal_parent, ((N * row) + col), ((N * new_row) + new_col))
        if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
            union(color_blindness_parent, (N * row + col), (N * new_row + new_col))

print(len(Counter(normal_parent).keys()), len(Counter(color_blindness_parent).keys()))

๊ฒฐ๊ตญ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ ํฌ๊ธฐํ•˜๊ณ  BFS๋กœ ํ‹€์—ˆ์”๋‹ˆ๋‹ค..

from collections import deque

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

idx = 0

board = []

for _ in range(N):

board.append(list(input()))

dx = [0, 0, -1, 1]

dy = [-1, 1, 0, 0]

visited = set()

deq = deque()

normal_answer = 0

for row in range(N):

for col in range(N):
    if (row, col) in visited: continue
    normal_answer += 1
    visited.add((row, col))
    deq.append((row, col))
    while deq:
        now_row, now_col = deq.popleft()
        for dir in range(4):
            new_row = now_row + dy[dir]
            new_col = now_col + dx[dir]
            if new_row < 0 or new_row >= N: continue
            if new_col < 0 or new_col >= N: continue
            if (new_row, new_col) in visited: continue
            if board[row][col] == board[new_row][new_col]:
                deq.append((new_row, new_col))
                visited.add((new_row, new_col))

visited = set()

deq = deque()

color_blindness_answer = 0

for row in range(N):

for col in range(N):
    if (row, col) in visited: continue
    color_blindness_answer += 1
    visited.add((row, col))
    deq.append((row, col))
    while deq:
        now_row, now_col = deq.popleft()
        for dir in range(4):
            new_row = now_row + dy[dir]
            new_col = now_col + dx[dir]
            if new_row < 0 or new_row >= N: continue
            if new_col < 0 or new_col >= N: continue
            if (new_row, new_col) in visited: continue
            if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
                deq.append((new_row, new_col))
                visited.add((new_row, new_col))

print(normal_answer, color_blindness_answer)

์™€ ๊ทผ๋ฐ R์ด๋ž‘ G ๋˜‘๊ฐ™์ด ๋งž์ถ”๊ณ  ๋‹ค์‹œ ๋Œ๋ฆฌ๋Š” ๊ฑฐ ๋ค ์ „๋‘๋‹ค ๋ค ์ „๋‘

์œ ๋‹ˆ์˜จํŒŒ์ธ๋“œ ์ฝ”๋“œ ๋ฐ˜๋ก€ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค


20

BBBBBRRRRRRRRRRRBBBB

BBBBBRRRRRRRRRRRBBBB

RBBBBBRRRRRRRRRRBBBB

RRRBBBBRRRRRRRRRBBBB

RRRBBBBRRRRRRRRRRBRB

GRRBBBBRRRRRRRRRRBRR

GGRRRRBBBRRRRRRRRBBB

GGGRRRBBBRRRRRRRRBBB

RRGGGGBBBRRRRRRRRBBB

BBGGGGBBBBRRRRRRRBBB

BBGGGGGBBBRRRRRRRBBB

GBGGGGGBRRRRRRRRRBBB

GGGGGGGGRRRRRRRRRBBB

GGGGGGGGGRRRRRRRRBBB

GGGGGGGGGGRRRRRRRBBB

RRGGGGGGGGGGRRRRRRBB

RRGGGGGGGGGGGGGGGRBB

RRRGGGGGGGGGGGGGGRBB

GGGGGGGBGGGGGGGGGGBB

RRRRGGGGGGGGGGGGGGGG

๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋‹ต์€ 11 6์ธ๋ฐ 12 7์ด ๋‚˜์˜ค๋„ค์šฉ

ํ•˜ ๊ทผ๋ฐ ์™œ ์•ˆ๋˜๋Š”์ง€๋Š” ์ €๋„ ์•„์ง ๋ชป์ฐพ๊ฒ ๋„ค์š”.. ์ซŒ ๋” ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šด๋‘ฅ

=======

@tgyuuAn ์ฐพ์•˜์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

for i in range(len(normal_parent)):

    print(i, " : ", normal_parent[i])

๋ฅผ ๋Œ๋ฆฌ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ๋‚˜์™€์š”

image

๊ทธ๋Ÿฐ๋ฐ ์‹ค์ œ๋กœ 361๋ฒˆ์งธ ๊ฐ’์„ ๋ณด๋ฉด ๋ถ€๋ชจ๊ฐ€ 100์ด์–ด์•ผ ํ•˜๋Š”๋ฐ ๋ถ€๋ชจ๊ฐ€ 360์œผ๋กœ ๋˜์–ด ์žˆ์–ด์š”(0~400๋ฒˆ๊ธฐ์ค€์œผ๋กœ index๋ฅผ ์žก์€ ๊ฒฝ์šฐ์ž…๋‹ˆ๋‹ค)

๊ทธ๋ž˜์„œ

image

print ์ถœ๋ ฅํ•ด์„œ ๋Œ๋ ค๋ณด๋‹ˆ๊นŒ

graph[360] ๊ฐ’์ด 100์œผ๋กœ ๋ณ€๊ฒฝ๋˜๊ธฐ ์ „์— ์ด๋ฏธ graph[361]์„ 360์œผ๋กœ ๋ฐ”๊ฟจ๊ธฐ ๋•Œ๋ฌธ์— graph[361] 100์œผ๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ์•ˆ๋œ ๊ฒƒ ๊ฐ™์•„์š”!!

๊ทธ๋ž˜์„œ

์ตœ์ข… print ๋ฌธ์„ ์ถœ๋ ฅํ•˜๊ธฐ ์ „์—, ํ•œ๋ฒˆ๋” find_parent()๋ฅผ ๋Œ๋ ค์„œ ๋ถ€๋ชจ๋…ธ๋“œ๋ฅผ ๊ฐ€๋ฅดํ‚ค๋„๋ก ๋‹ค์‹œ ์—…๋ฐ์ดํŠธ ํ•ด์ฃผ์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค....

์• ๋ ต๋„ค์š”

์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๊ฐ€ ์›๋ž˜ ์ด๋Ÿฐ ๊ฒฝ์šฐ๋ฅผ ๋‹ค ์ƒ๊ฐํ•ด์ฃผ์–ด์•ผ ํ• ๊นŒ์š”................???

๋Œ€๋ฐ•์ ์ด๋„ค๋‡จ.. ์™€ํ์ฅฌ ๋Œ€๋ฐ•...

์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๋งˆ์ง€๋ง‰์— find_parent() ๋Œ๋ ค์ฃผ์–ด์„œ ๋ณ€๊ฒฝ๋œ ์ง„์งœ ๋ถ€๋ชจ๋ฅผ ์ฐพ์•„์ค˜์•ผํ•ด์š”

์ €๋ ‡๊ฒŒ ํ•˜๋ฌœ ์‹œ๊ฐ„์•ˆ์— ์„ธ์žŽ ๋˜๋‚˜์š”?!?!?

@H0ngJu
Copy link
Collaborator Author

H0ngJu commented May 27, 2024

BFS/DFS๋กœ ํ’€๋ฆด ๊ฑฐ ์•Œ๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๋กœ๋„ ํ’€๋ฆด ๊ฒƒ ๊ฐ™์•„์„œ ํŠธ๋ผ์ด ํ•ด๋ดค๋Š”๋ฐ ์™œ ์•ˆ๋˜๋Š” ์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š” .......... ๋„์™€์ฃผ์„ธ์š” ใ… ใ… ใ… ใ… ใ… ใ… ใ… 

from collections import Counter

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

board = []

def find_parent(graph, element):

if graph[element] == element: return element
parent = graph[element]
graph[element] = find_parent(graph, parent)
return graph[element]

def union(graph, first, second):

x = find_parent(graph, first)
y = find_parent(graph, second)
if x == y: return
x, y = min(x, y), max(x, y)
graph[y] = x
return

normal_parent = []

color_blindness_parent = []

idx = 0

for _ in range(N):

row = list(input())
for element in row:
    normal_parent.append(idx)
    color_blindness_parent.append(idx)
    idx += 1
board.append(row)

dx = [0, 0, -1, 1]

dy = [-1, 1, 0, 0]

for row in range(N):

for col in range(N):
    for dir in range(4):
        new_row = row + dy[dir]
        new_col = col + dx[dir]
        if new_row < 0 or new_row >= N: continue
        if new_col < 0 or new_col >= N: continue
        if board[row][col] == board[new_row][new_col]:
            union(normal_parent, ((N * row) + col), ((N * new_row) + new_col))
        if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
            union(color_blindness_parent, (N * row + col), (N * new_row + new_col))

print(len(Counter(normal_parent).keys()), len(Counter(color_blindness_parent).keys()))

๊ฒฐ๊ตญ ์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ ํฌ๊ธฐํ•˜๊ณ  BFS๋กœ ํ‹€์—ˆ์”๋‹ˆ๋‹ค..

from collections import deque

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

idx = 0

board = []

for _ in range(N):

board.append(list(input()))

dx = [0, 0, -1, 1]

dy = [-1, 1, 0, 0]

visited = set()

deq = deque()

normal_answer = 0

for row in range(N):

for col in range(N):
    if (row, col) in visited: continue
    normal_answer += 1
    visited.add((row, col))
    deq.append((row, col))
    while deq:
        now_row, now_col = deq.popleft()
        for dir in range(4):
            new_row = now_row + dy[dir]
            new_col = now_col + dx[dir]
            if new_row < 0 or new_row >= N: continue
            if new_col < 0 or new_col >= N: continue
            if (new_row, new_col) in visited: continue
            if board[row][col] == board[new_row][new_col]:
                deq.append((new_row, new_col))
                visited.add((new_row, new_col))

visited = set()

deq = deque()

color_blindness_answer = 0

for row in range(N):

for col in range(N):
    if (row, col) in visited: continue
    color_blindness_answer += 1
    visited.add((row, col))
    deq.append((row, col))
    while deq:
        now_row, now_col = deq.popleft()
        for dir in range(4):
            new_row = now_row + dy[dir]
            new_col = now_col + dx[dir]
            if new_row < 0 or new_row >= N: continue
            if new_col < 0 or new_col >= N: continue
            if (new_row, new_col) in visited: continue
            if board[row][col] in ("R", "G") and board[new_row][new_col] in ("R", "G") or board[row][col] == board[new_row][new_col] == "B":
                deq.append((new_row, new_col))
                visited.add((new_row, new_col))

print(normal_answer, color_blindness_answer)

์™€ ๊ทผ๋ฐ R์ด๋ž‘ G ๋˜‘๊ฐ™์ด ๋งž์ถ”๊ณ  ๋‹ค์‹œ ๋Œ๋ฆฌ๋Š” ๊ฑฐ ๋ค ์ „๋‘๋‹ค ๋ค ์ „๋‘

์œ ๋‹ˆ์˜จํŒŒ์ธ๋“œ ์ฝ”๋“œ ๋ฐ˜๋ก€ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค


20

BBBBBRRRRRRRRRRRBBBB

BBBBBRRRRRRRRRRRBBBB

RBBBBBRRRRRRRRRRBBBB

RRRBBBBRRRRRRRRRBBBB

RRRBBBBRRRRRRRRRRBRB

GRRBBBBRRRRRRRRRRBRR

GGRRRRBBBRRRRRRRRBBB

GGGRRRBBBRRRRRRRRBBB

RRGGGGBBBRRRRRRRRBBB

BBGGGGBBBBRRRRRRRBBB

BBGGGGGBBBRRRRRRRBBB

GBGGGGGBRRRRRRRRRBBB

GGGGGGGGRRRRRRRRRBBB

GGGGGGGGGRRRRRRRRBBB

GGGGGGGGGGRRRRRRRBBB

RRGGGGGGGGGGRRRRRRBB

RRGGGGGGGGGGGGGGGRBB

RRRGGGGGGGGGGGGGGRBB

GGGGGGGBGGGGGGGGGGBB

RRRRGGGGGGGGGGGGGGGG

๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋‹ต์€ 11 6์ธ๋ฐ 12 7์ด ๋‚˜์˜ค๋„ค์šฉ
ํ•˜ ๊ทผ๋ฐ ์™œ ์•ˆ๋˜๋Š”์ง€๋Š” ์ €๋„ ์•„์ง ๋ชป์ฐพ๊ฒ ๋„ค์š”.. ์ซŒ ๋” ์ƒ๊ฐํ•ด๋ณด๊ฒ ์Šด๋‘ฅ

@tgyuuAn ์ฐพ์•˜์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

for i in range(len(normal_parent)):

    print(i, " : ", normal_parent[i])

๋ฅผ ๋Œ๋ฆฌ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ๋‚˜์™€์š”
image
๊ทธ๋Ÿฐ๋ฐ ์‹ค์ œ๋กœ 361๋ฒˆ์งธ ๊ฐ’์„ ๋ณด๋ฉด ๋ถ€๋ชจ๊ฐ€ 100์ด์–ด์•ผ ํ•˜๋Š”๋ฐ ๋ถ€๋ชจ๊ฐ€ 360์œผ๋กœ ๋˜์–ด ์žˆ์–ด์š”(0~400๋ฒˆ๊ธฐ์ค€์œผ๋กœ index๋ฅผ ์žก์€ ๊ฒฝ์šฐ์ž…๋‹ˆ๋‹ค)
๊ทธ๋ž˜์„œ
image
print ์ถœ๋ ฅํ•ด์„œ ๋Œ๋ ค๋ณด๋‹ˆ๊นŒ
graph[360] ๊ฐ’์ด 100์œผ๋กœ ๋ณ€๊ฒฝ๋˜๊ธฐ ์ „์— ์ด๋ฏธ graph[361]์„ 360์œผ๋กœ ๋ฐ”๊ฟจ๊ธฐ ๋•Œ๋ฌธ์— graph[361] 100์œผ๋กœ ์—…๋ฐ์ดํŠธ๊ฐ€ ์•ˆ๋œ ๊ฒƒ ๊ฐ™์•„์š”!!
๊ทธ๋ž˜์„œ
์ตœ์ข… print ๋ฌธ์„ ์ถœ๋ ฅํ•˜๊ธฐ ์ „์—, ํ•œ๋ฒˆ๋” find_parent()๋ฅผ ๋Œ๋ ค์„œ ๋ถ€๋ชจ๋…ธ๋“œ๋ฅผ ๊ฐ€๋ฅดํ‚ค๋„๋ก ๋‹ค์‹œ ์—…๋ฐ์ดํŠธ ํ•ด์ฃผ์–ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค....
์• ๋ ต๋„ค์š”
์œ ๋‹ˆ์˜จ ํŒŒ์ธ๋“œ๊ฐ€ ์›๋ž˜ ์ด๋Ÿฐ ๊ฒฝ์šฐ๋ฅผ ๋‹ค ์ƒ๊ฐํ•ด์ฃผ์–ด์•ผ ํ• ๊นŒ์š”................???

๋Œ€๋ฐ•์ ์ด๋„ค๋‡จ.. ์™€ํ์ฅฌ ๋Œ€๋ฐ•...

์ƒ๊ฐํ•ด๋ณด๋‹ˆ ๋งˆ์ง€๋ง‰์— find_parent() ๋Œ๋ ค์ฃผ์–ด์„œ ๋ณ€๊ฒฝ๋œ ์ง„์งœ ๋ถ€๋ชจ๋ฅผ ์ฐพ์•„์ค˜์•ผํ•ด์š”

์ €๋ ‡๊ฒŒ ํ•˜๋ฌœ ์‹œ๊ฐ„์•ˆ์— ์„ธ์žŽ ๋˜๋‚˜์š”?!?!?

image

์˜ˆ์•• ํ†ต๊ณผ๋ฉ๋‹ˆ๋‹น ~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants